<template>
    <view>
        <status-bar :title="title"></status-bar>
        <Search :placeTxt="placeTxt" :Val="query_text" @Search="searchData"></Search>
        <view class="Wrapper">
            <view class="list" @click="$Means.Sublevel(item)" v-for="(item, index) in pageData" :key="index">
                <image :src="$imgUrls(item.img)" mode="aspectFit"></image>
            </view>
        </view>
        <emptys empty="search" v-if="!pageData.length"></emptys>
    </view>
</template>

<script>
    import { mapState } from 'vuex';
    import api from './api.js';
    import Search from '@/classification/components/Search.vue';
    export default {
        components: {
            Search
        },
        data() {
            return {
                placeTxt: '',
                title: '',
                pt: '4',
                type: '3',
                list_id: 0, // 37803
                label_id: 0, // 1342
                query_text: '',
                page: 1,
                limit: 20,
                getMore: true,
                pageData: []
            };
        },
        onLoad(opt) {
            if (opt.pt) this.pt = opt.pt;
            if (opt.type) this.type = opt.type;
            if (opt.list_id) this.list_id = opt.list_id;
            if (opt.label_id) this.label_id = opt.label_id;
            if (opt.val) this.query_text = opt.val;
            this.init();
        },
        methods: {
            async init() {
                let reuesetObj = {
                    pt: this.pt,
                    type: this.type,
                    list_id: this.list_id,
                    label_id: this.label_id,
                    page: this.page,
                    limit: this.limit,
                    query_text: this.query_text
                };
                const requsetResult = await api.dataQuery(reuesetObj);
                this.title = requsetResult.title;
                this.placeTxt = requsetResult.query_text;
                const result = requsetResult.list || [];
                this.page == 1 ? (this.pageData = result) : (this.pageData = [...this.pageData, ...result]);
                if (result.length < this.limit) this.getMore = false;
            },
            searchData(e) {
                this.query_text = e;
                this.page = 1;
                this.getMore = true;
                this.init();
            }
        },
        onReachBottom() {
            if (!this.getMore) return;
            this.page++;
            this.init();
        }
    };
</script>

<style lang="scss">
    page {
        background-color: $page;
        padding-bottom: 24rpx;
    }
</style>
<style lang="scss" scoped>
    .Wrapper {
        width: 710rpx;
        margin: 20rpx auto 0;
        display: grid;
        grid-template-columns: repeat(4, 1fr);
        gap: 20rpx;
        .list {
            height: 160rpx;
            background-color: #fff;
            border-radius: 10rpx;
            padding: 20rpx;
        }
    }
</style>
